package com.auxgroup.hr.front.service.process.impl;

import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModAttT;
import com.auxgroup.hr.front.dao.domain.PsCWfAttOprT;
import com.auxgroup.hr.front.dao.repository.PsCModAttTRepository;
import com.auxgroup.hr.front.dao.repository.PsCWfAttOprTRepository;
import com.auxgroup.hr.front.service.process.ModAttTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by nitongqian on 2019/1/19.
 */
@Service("modAttTService")
public class ModAttTServiceImpl implements ModAttTService {

    @Autowired
    private PsCModAttTRepository psCModAttTRepository;
    @Autowired
    private PsCWfAttOprTRepository psCWfAttOprTRepository;
    @Override
    public List<PsCModAttT> getWfFiles(String cTransactionNbr, UserDTO user) {
        List<PsCModAttT> mats = psCModAttTRepository.findByCTransactionNbr(cTransactionNbr);
        return mats.stream().filter(mat -> {
            List<PsCWfAttOprT> oprts = psCWfAttOprTRepository.findByCTransactionNbrAndSeqnbr(cTransactionNbr, mat.getSeqnbr());
            return oprts.isEmpty() || oprts.stream().map(oprt -> oprt.getOprid()).collect(Collectors.toSet()).contains(user.getOprId());
        }).collect(Collectors.toList());
    }
}
